package pl.ptemich.tankwars.objects;

import org.newdawn.slick.Image;

public abstract class MovingObject extends PhysicalObject {

  private Float speedX = 0f;
  
  private Float speedY = 0f;
  
  protected Float targetX;
  
  protected Float targetY;  
  
  public void moveTo(int x, int y) {
    this.targetX = 1f * x;
    this.targetY = 1f * y;
  }
  
  public MovingObject(Image view) {
    this(view, null, null);
  }
  
  public MovingObject(Image view, Float speedX, Float speedY) {
    super(view);
    
    this.speedX = speedX;
    this.speedY = speedY;
    
    if (speedX == null) {
      this.speedX = 0f;
    }
    
    if (speedY == null) {
      this.speedY = 0f;
    }
  }

  public void update(int delta) {
    this.moveObject(delta);
  }

  private void moveObject(int delta) {
    posX += speedX * delta;
    posY += speedY * delta;
  }
  
  
}
